//
//  AccountController.swift
//  SecretChat
//
//  Created by TimTiger on 16/6/21.
//  Copyright © 2016年 TimTiger. All rights reserved.
//

import UIKit

private let shareInstance = AccountController()

/// 用户账号管理
class AccountController: NSObject {
    
    class var shareController: AccountController  {
        return shareInstance
    }
    
    lazy var currentUser: SCUserInfo = SCUserInfo()
    
    override init() {
        super.init()
        self.initCurrentUser()
    }
    
    //MARK: Private API
    private func initCurrentUser() {
        let pushToken =  NotificationController.pushToken()
        if String.hasCharacter(pushToken) {
            let userInfo = SCDBUser.userInfoWithUserID(pushToken!)
            if userInfo != nil {
                self.currentUser = userInfo!
            }
        }
    }
    
    //MARK: Public API
    func updateCurrentUser() {
        let pushToken =  NotificationController.pushToken()
        if String.hasCharacter(pushToken) {
            self.currentUser.pushToken = pushToken!
            self.currentUser.userID = pushToken!
        }
        self.currentUser.update()
    }
    
    
}
